package com.sl.service;

import com.sl.mapper.OptionMapper;
import com.sl.pojo.Option;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class OptionService {

    @Resource
    private OptionMapper optionMapper;

    public List<Option> findAll(){
        return  optionMapper.selectAll();
    }
    //根据主键找
    public Option findById(Integer id){
        Option option = optionMapper.selectByPrimaryKey(id);
        return option;
    }
    //根据QuestionOption。问题的选项。找
    public Option findByQuestionOption(String qOption){
        Example example = new Example(Option.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("questionOption",qOption);
        Option option = optionMapper.selectOneByExample(example);
        return option;
    }
    //增加一个选项
    public void add(Option option){
          optionMapper.insertSelective(option);
    }

}
